#!/usr/bin/python
# -*- coding: utf-8 -*-
__version__ = 1.05
#import OF3D_TDCmd.OF3D_zOpsMeshOrig as mops
#reload(mops)
#a = mops.ShapeOrigOprate()
"""
#up data note:
#v1.0 the first version
#v1.01 add funtion replace UV command
#v1.02 updata seekOutBlendshapeTarget give it input flag function
    1.03:add funtion softEdgeShapeOrig
    1.04:repair if mesh has ShapeDeformed getMeshOrig wrong bug
    1.05:2012-06-15 repair softEdgeShapeOrig bug of <Current selection doesn't match required selection type.>
"""
import maya.cmds as mc
import maya.mel as mel
import re
from maya import OpenMaya as om
import maya.OpenMayaAnim as oma
import tools_Persional.LZ_Tools.LZ_Tools.OF3D_PublicClass.OF3D_zchPipePublicClass as PublicClass
import tools_Persional.LZ_Tools.LZ_Tools.OF3D_PublicClass.searchByName as sbn

class ShapeOrigOprate(PublicClass.PublicClass,sbn.Matching):
    def meshCompareSelectOption(self):
        btCommand = "import %s as ms\nms.ShapeOrigOprateCls.meshCompareSelect()"%(__name__)
        radioName = "mcso_MatchNumFace_rbg"
        cCommand = 'import OF3D_PublicClass.uiAbout as ui\nui.UIAboutCls.uiReadAndSetOptionVar(e=True,buttonType="radioButtonGrp",buttonName="%s")'%(radioName)
        winName = "meshCompareSelectOption_win"
        resetCmd = "from maya import cmds\ncmds.radioButtonGrp('%s',e=True,sl=1)"%(radioName)
        if mc.window(winName, exists=True):
            mc.deleteUI(winName, window=True)
        mc.window(winName,title="OF-Mesh Compare Option",menuBar=True)
        #Edit Help
        self.winMenuBar(resetCmd,"Check Pair Pologon Topology.mht")
        #RestTool Apply Close
        masterLayout = self.winMasterLayout(resetCmd,btCommand,winName)
        slv = self.uiReadAndSetOptionVar(q=True,default=1,buttonType="radioButtonGrp",buttonName=radioName )
        mc.radioButtonGrp(radioName,label="Match Num Face:",nrb=2,la2=["Yes","No"],sl=slv,cc=cCommand)
        mc.showWindow(winName)
        
    def meshCompareSelect(self):
        #
        objs = mc.ls(sl=True,ap=True)
        if len(objs)!=2:
            self.mayaError("No 2 mesh selected! //")
            return
        for obj in objs:
            if not mc.objectType( self.getShapeName(obj) ,isType="mesh" ):
                self.mayaError("No 2 mesh selected! //")
                return
        mnfOpv = mc.optionVar(q="mcso_MatchNumFace_rbg_opv")
        if mnfOpv==1:
            matchFaceNums = True
        else:
            matchFaceNums = False
        #
        obja = self.getShapeName( objs[0] )
        objb = self.getShapeName( objs[1] )
        if self.meshCompare(obja,objb,matchNumFace=matchFaceNums):
            self.mayaPrint( "Topology: OK %s = %s."%(objs[0],objs[1]) )
            return True
        else:
            self.mayaWarning( "Topology: Error %s != %s."%(objs[0],objs[1]) )
            return False
            
    def selectOrig(self):
        origList = []
        inList = mc.ls(sl=1,ap=1)
        if inList == []:
            self.mayaWarning("No object selected.")
            return 0
        #add meshShape orig to the list
        for o in inList:
            origName = self.getMeshOrig(o)
            if origName!=None:
                origList.append(origName)
        if origList!=[]:
            mc.select(origList)
        else:
            self.mayaPrint("No shapeOrig.")
    def shareFirstOrigToOther(self):
            sels = mc.ls(sl=1,ap=1)
            if len(sels)<2:
                    self.mayaError("Must more than 2 object selected.")
            else:
                    self.shareFirstOrigToOtherFun(sels)
    def delSelMeshRepeatFace(self):
        sels = mc.ls(sl=True,ap=True)
        for x in sels:
            itShapes = mc.listRelatives(x,shapes=True,type="mesh")
            if itShapes!=None and ("|" not in itShapes[0]):
                self.delRepeatFace( itShapes[0] )
        self.mayaPrint( "Delete all repeat face of your selected polygon //" )
    #delete a list or all or your selected object shapeOrig-----------------------
    def deleteAllUnuseOrig(self,inObj=None,printer=True):
        if inObj==None or inObj==0:
            seleds = mc.ls(sl=True)
            for x in seleds:
                self.deleteUnuseOrig(x,printer)
        else:
            if mc.objExists(inObj):
                self.deleteUnuseOrig(inObj,printer)
            else:
                self.mayaWarning("No object %s."%(inObj))
ShapeOrigOprateCls = ShapeOrigOprate()
MeshShape = ShapeOrigOprate()
